import React, { useEffect, useState } from "react";
import { Button, Checkbox, Form, type FormProps, Input, message } from "antd";
import axios from "axios";
const Index: React.FC = () => {
  type FieldType = {
    username?: string;
    password?: string;
    remember?: string;
  };
  let [list,setList]=useState<any>([])
  let [values,setValues]=useState<any>({})
  let [my,setMy]=useState<any>([])
  const redner=()=>{
axios.post('/api/lt',{params:{values}}).then((resp)=>{
      let {code,msg}=resp.data
      console.log(msg)
      if (code==200) {
        list.push(msg)
      }
    })
  }
  useEffect(()=>{
redner()
  },[])
  const onFinish: FormProps<FieldType>["onFinish"] = (values) => {
    console.log(values.username);
    setValues(values)
    redner()
  };
  return (
    <div>
      <h3>聊天机器人</h3>
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ maxWidth: 600 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item<FieldType>
          label="请输入聊天内容"
          name="username"
          rules={[{ required: true, message: "Please input your username!" }]}
        >
          <Input />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit">
            发送
          </Button>
        </Form.Item>
      </Form>
      {list.length>0 ? (list.map((v:any,i:any)=><div>机器人回复:{v}</div>)):("输入的无效")}
    </div>
  );
};
export default Index;
